/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[JoinThread.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package thread;

/**
 * 线程的join<br/>
 * 
 * 一个线程如果执行join语句, 那么就有新的线程加入, 执行该语句的线程必须要让步给新加入的线程先完成任务, 然后才能继续执行<br/>
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class JoinThread {

	public static void main(String[] args) {
		Mom mom = new Mom();
		mom.start();
	}
}

/**
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 *
 */
class Mom extends Thread {

	@Override
	public void run() {
		System.out.println("妈妈洗菜...");
		System.out.println("妈妈切菜...");
		System.out.println("妈妈准备炒菜, 发现没有酱油了..");
		// 叫儿子去打酱油
		Son s = new Son();
		s.start();
		try {
			s.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println("妈妈继续炒菜...");
		System.out.println("全家一起吃饭...");
	}
}

class Son extends Thread {

	@Override
	public void run() {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("儿子下楼...");
		System.out.println("儿子一直往前走...");
		System.out.println("儿子打完酱油了...");
		System.out.println("上楼, 把酱油给老妈...");
	}
}